#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    _log_dlg=new LoginDialog();
    _reg_dlg=new RegisterDialog();
    reset_dlg=new ResetpswDialog();
    m_stackwidget=new QStackedWidget(this);

    setCentralWidget(m_stackwidget);

    m_stackwidget->addWidget(_log_dlg);
    m_stackwidget->addWidget(_reg_dlg);
    m_stackwidget->addWidget(reset_dlg);
    setupConnection();
}

void MainWindow::setupConnection(){
    connect(_log_dlg,&LoginDialog::SwitchToReg,this,&MainWindow::SlotSwitchToReg);
    connect(_reg_dlg,&RegisterDialog::switchtoLogin,this,&MainWindow::SlotSwtichToLogin);
    connect(_log_dlg,&LoginDialog::SwitchToResetpsw,this,&MainWindow::SlotSwtichToResetpsw);
    connect(reset_dlg,&ResetpswDialog::SwitchToLogin,this,&MainWindow::SlotSwtichToLogin);
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::SlotSwitchToReg(){
    m_stackwidget->setCurrentWidget(_reg_dlg);
}
void MainWindow::SlotSwtichToLogin(){
    m_stackwidget->setCurrentWidget(_log_dlg);
}
void MainWindow::SlotSwtichToResetpsw(){
    m_stackwidget->setCurrentWidget(reset_dlg);
}
